//
//  DistrictViewController.m
//  cityStar
//
//  Created by joyban on 15-2-3.
//  Copyright (c) 2015年 tiny. All rights reserved.
//

#import "DistrictViewController.h"
#import "selectDistrict.h"

@interface DistrictViewController ()

@property(nonatomic,strong)NSArray *idArray;
@property(nonatomic,strong)NSArray *nameArray;
@property(nonatomic,strong)NSArray *isopenArray;
@property (weak, nonatomic) IBOutlet UITableView *DistrictTabel;

@end

@implementation DistrictViewController

-(void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"选择区";
    [self addBackButton];
    self.nameArray = [[NSArray alloc]init];
    self.idArray = [[NSArray alloc]init];
    self.isopenArray = [[NSArray alloc]init];
    [self webRequest_citydataWithDetailID:self.Districtid];
}

//-(void)back
//{
//    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

-(void)webRequest_citydataWithDetailID:(NSString *)sendeid
{
    NSString *getPul = [NSString stringWithFormat:@"%@/%@",KInterface_getRegion,sendeid];
    [HttpRequestManager getMethod:getPul parameters:nil completedMainBlock:^(BOOL success, id response, NSString *errMsg) {
        if (success) {
            DLog(@"%@",response);
            [[selectDistrict shardDistrictInfo]setClasscityArray:response[@"value"]];
            self.nameArray = [selectDistrict shardDistrictInfo].DistrictNameArray;
            self.idArray = [selectDistrict shardDistrictInfo].DistrictIdArray;
            self.isopenArray = [selectDistrict shardDistrictInfo].DistrictIsopenArray;
            [self.DistrictTabel reloadData];
        }else{
            DLog(@"%@",errMsg);
            [SVProgressHUD showErrorWithStatus:errMsg];
        }
    }];
}

#pragma mark - UITableViewDelegate
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.nameArray.count;
}

#pragma mark - UITableViewDataSource
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *ListdetailCell = [tableView dequeueReusableCellWithIdentifier:@"CellID"];
    if (ListdetailCell==nil) {
        ListdetailCell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CellID"];
    }
    ListdetailCell.selectionStyle = UITableViewCellSelectionStyleGray;
    ListdetailCell.textLabel.text = self.nameArray[indexPath.row];
    return ListdetailCell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"BackDistrict" object:[NSString stringWithFormat:@"%li",indexPath.row]];

    [[NSNotificationCenter defaultCenter] postNotificationName:@"backAdd" object:nil];
    [tableView reloadData];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
